let app = getApp();
let luoke = require("../../utils/luoke");
Page({
  data: {
       headImg: "/public/icon/people_head_img.png",
       loginOutIcon: "/public/icon/log_out.png",
       rightIcon: "/public/icon/chevron_right_btn.png",
       icon1: "/public/icon/people_icon1.png",
       icon2: "/public/icon/people_icon2.png",
       icon3: "/public/icon/people_icon3.png",
       icon4: "/public/icon/people_icon4.png",
       icon5: "/public/icon/people_icon5.png",
       icon9: "/public/icon/people_shop.png",
       icon10: "/public/icon/people_icon10.png",
       userInfo: "",
   
       supplyPriceStatus: false,
       token: ""
  },
  
  onLoad (option) {
       console.log(option)
  },
  onShow () {
      // this.init()
      let userInfo = wx.getStorageSync('userInfo');
      let supplyPriceStatus = wx.getStorageSync('supplyPriceStatus');
      let token = "";
      if (!userInfo) { return ;} 
    
      // luoke.outTimeFn()
      token = userInfo.access_id;
      this.setData({
          token: token,
          userInfo: userInfo,
          supplyPriceStatus: supplyPriceStatus
      }, function () {

        
        this.getSettledFn()
      })
     
  },
  init: function () {
      let userInfo = wx.getStorageSync('userInfo');
      let supplyPriceStatus = wx.getStorageSync('supplyPriceStatus');
      let token = userInfo.access_id;
      this.setData({
          token: token,
          userInfo: userInfo,
          supplyPriceStatus: supplyPriceStatus
      })
  },


  
  getSettledFn: function () {
    let _this = this;
    let token = this.data.token;
    let url = app.globalData.url;
    let userInfo = this.data.userInfo;
    // wx.showLoading({
    //   title: '加载中'
    // })
    wx.request({
      url: url, 
      method: "get",
      data: {
        api: "app.user.getBusinessInfo",
        storeId: 1,
        storeType: 6,
        accessId: token
      },
      header: {
        'content-type': 'application/json'  
      },
      success (res) {
         // wx.hideLoading()
          let resData = res.data;
          if (res.data.code == 200) {
              let resData = res.data.data;
              userInfo.submitFlag = resData.submitFlag;
              userInfo.examineFlag = resData.examineFlag;
              userInfo.signatoryName = resData.signatoryName;
              //  userInfo.submitFlag = 0;
              //  userInfo.examineFlag = 0;
              wx.setStorageSync('userInfo', userInfo);
              _this.setData({
                  submitInfo: resData,
                  submitFlag: resData.submitFlag,
                  examineFlag: resData.examineFlag,
                  industryIndex: resData.industry || 0,
                  userType: resData.signatoryType,
                  userInfo: userInfo
              })
          }
      }
    })      
  },
  loginOutFn: function () {
      wx.showModal({
          title: "提示",
          content: "退出登录？",
          success (res) {
              if (res.confirm) {
                  wx.clearStorage()
                
                 
                  wx.navigateTo({
                      url: '/pages/login/login'
                  })
              }
          }
      })
  },
  supplyPriceStatusFn: function () {
       let supplyPriceStatus = this.data.supplyPriceStatus; 
       let _this = this;
       let message = supplyPriceStatus?"关闭供货价数据吗？":"确认开启展示供货价数据吗？"
       let userInfo = this.data.userInfo;
       
       if (!userInfo) {
           wx.showToast({
               title: "请登录",
               icon: "error"
           })
           setTimeout(()=> {
               wx.navigateTo({
                   url: "/pages/login/login"
               })
           }, 2000)
           return ;
       }
       wx.showModal({
           title: "",
           content: message,
           success (res) {
                if (res.confirm) {
                    supplyPriceStatus = !_this.data.supplyPriceStatus;
                     _this.setData({
                        supplyPriceStatus: supplyPriceStatus
                     })
                     wx.setStorage({
                         key: "supplyPriceStatus",
                         data: supplyPriceStatus
                     })     
                }
           }
       })
  },
  goDetailFn: function (e) {
      let userInfo = this.data.userInfo;
      let id = parseInt(e.currentTarget.dataset.id);
      if (!userInfo) {
          wx.showToast({
              title: "请登录",
              icon: "error"
          })
          setTimeout(()=> {
              wx.navigateTo({
                  url: "/pages/login/login"
              })
          }, 2000)
          return ;
      }
      wx.navigateTo({
        url: "/pages/order/order?id=" + id
      })
  }
})